package test;

import com.alibaba.fastjson.JSON;
import com.itheima.domain.Book;
import com.itheima.domain.Chapter;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author xgy
 * @date 2020-09-12 14:55
 */

public class PaChu {
    public static ArrayList<Book> list = new ArrayList<>();
    public static ArrayList<Chapter> zhangJieNeiRong = new ArrayList<>();

    public static Document getBook() throws IOException {
        //爬取
        Document document = Jsoup.connect("https://hualsy.com/book/1238.html").timeout(0).get();
        String bookTitle = document.select(".bookTitle").text();
        Element booktag = document.select(".booktag").get(0);
        String writer = booktag.child(0).text();
        String fenLei = booktag.child(1).text();
        String ziShu = booktag.child(2).text();
        String yueDuShu = booktag.child(3).text();
        String zhuangTai = booktag.child(4).text();
        String xiaoShuoJianJie = document.select("#bookIntro").text();
        Book book = new Book("1",bookTitle,writer,fenLei,ziShu,yueDuShu,zhuangTai,xiaoShuoJianJie);
        list.add(book);
        String s = JSON.toJSONString(list);
        BufferedWriter bw = new BufferedWriter(new FileWriter("reptileDemozcy/books/book.txt",false));
        bw.write(s);
        bw.close();
        return document;
    }
}
